<template>
	<view class="">
		<view class="inviteCraftsmen"
			:class="options.type == 1 ? '' :options.type ==2 ? 'inviteCraftsmen2':'inviteCraftsmen3'">
			<block v-if="options.type == 3">
				<view style="position: absolute;;top: 94rpx;width: 80vw;">
					<view class="cf f28 tac">
						<view class="mt36">
							被邀请工匠入驻，您可立即获￥{{data.register}} 奖励
						</view>
						<view class="mt24" v-for="(i,k) in data.shop_pay" :key="k">
							被邀请工匠消费满{{i.reward}}元，您可获￥{{i.limit}} 奖励
						</view>
					</view>
					<view class="fb tac" style="color: #FF0032;margin-top: 360rpx;">

						<text style="font-size: 60rpx;">￥</text>
						<text style="font-size: 120rpx;">{{data.shop_price}}</text>
						<!-- 邀请新工匠注册可奖励 <text class="error f48 mr4">{{data.register}}</text> 元 -->
					</view>

				</view>
			</block>
			<!-- 工匠 -->
			<block v-if="options.type == 2">
				<view style="position: absolute;;top: 480rpx;width: 80vw;">
					<view class=" fb tac" style="color: #FE7420;">

						<text style="font-size: 60rpx;">￥</text>
						<text style="font-size: 120rpx;">{{data.worker_price}}</text>
						<!-- 邀请新工匠注册可奖励 <text class="error f48 mr4">{{data.register}}</text> 元 -->
					</view>
					<view class="cf f28 tac">
						<view class="mt36">
							被邀请工匠入驻，您可立即获￥{{data.register}} 奖励
						</view>
						<view class="mt24" v-for="(i,k) in data.pay" :key="k">
							被邀请工匠消费满{{i.reward}}元，您可获￥{{i.limit}} 奖励
						</view>
					</view>
				</view>
			</block>
			<!-- 用户 -->
			<block v-if="options.type == 1">
				<view style="position: absolute;;top: 200rpx;">
					<view class="aa1 flex_yy_center fb" style="color: #FE7420">
						<view class="">
							被分享用户购买产品
						</view>
						<view class="flex_ac mt24">
							您即可获得产品价格的
							<text class="error f48 mr4">{{data.user_commission}}佣金</text>
						</view>
					</view>
					<view class="cf f24 mt16 tac">
						例：被邀请的用户在平台下单5000元产品
					</view>
					<view class=" mt24 cf tac">
						您可获
						<text class="fb f48 ml20">{{data.user_commission_price}}</text>
					</view>
				</view>
			</block>

			<button class="buttonOpen" open-type="share" v-if="options.type == 1">
				去邀请
			</button>
			<button class="buttonOpen buttonOpen2" open-type="share" v-if="options.type == 2">
				去邀请
			</button>
			<button class="buttonOpen buttonOpen3" open-type="share" v-if="options.type == 3">
				去邀请
			</button>

		</view>
	</view>



</template>

<script>
	export default {
		data() {
			return {
				data: {},
				showSpecialBackground: false,
				options: null,
				imageUrl: '',
				unititle: '',
			}
		},
		onLoad(options) {
			this.options = options
			this.getNums()
			this.checkUserLevel()
		},
		onShareAppMessage() {
			this.$store.dispatch('common/getRelay')
			return {
				title: this.unititle,
				imageUrl: this.imageUrl,
				path: `pages/tabbarcompotant/index/landlord?invitation_code=${uni.getStorageSync('wanlshop:user').uuid}`,
				success() {
					console.log('分享成功');

				},
				fail(err) {
					console.error('分享失败', err);
				}
			};
		},
		methods: {

			// 检查用户等级并设置背景
			checkUserLevel() {
				try {
					// 获取本地缓存中的用户数据
					const userData = uni.getStorageSync('wanlshop:user');
					if (this.options.type == 1) {
						// 检查level是否为1或5
						this.showSpecialBackground = true;
						console.log('用户等级为1或5，显示特殊背景');
						uni.setNavigationBarTitle({
							title: '邀请用户'
						});
						this.imageUrl = "https://img.aibbyp.com/wechatUser/yhfx1.png"
						this.unititle = '邀请用户'
					} else if (this.options.type == 2) {
						uni.setNavigationBarTitle({
							title: '邀请工匠'
						});
						this.imageUrl = "https://img.aibbyp.com/wechatUser/gjfx1.png"
						this.unititle = '邀请工匠'
						console.log('未获取到用户缓存数据，显示普通背景');
						this.showSpecialBackground = false;
					} else {
						uni.setNavigationBarTitle({
							title: '邀请商家'
						});
						this.unititle = '邀请商家'
						this.imageUrl = "https://img.aibbyp.com/wechatUser/sjfx1.png"
					}
				} catch (error) {
					console.error('获取用户缓存数据失败:', error);
					this.showSpecialBackground = false;
				}
			},
			getNums() {
				this.$api.get({
					url: '/index/getWorkerSharePage',
				}).then(res => {
					this.data = res
				})
			},
		},

	}
</script>

<style>
	.aa1 {
		font-size: 32rpx;
		padding: 14rpx 42rpx;
		color: #FA060F;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}

	.buttonOpen {
		width: 472rpx;
		height: 104rpx;
		background: linear-gradient(180deg, #FFFFFF 0%, #FFE8D4 32%, #FFECD7 52%, #FFFFFF 100%);
		box-shadow: 0rpx 4rpx 10rpx 0rpx #B44813;
		border-radius: 200rpx 200rpx 200rpx 200rpx;
		font-size: 48rpx;
		color: #FF6816;
		text-align: center;
		line-height: 104rpx;
		position: absolute;
		top: 1048rpx;
		left: calc(50% - 236rpx);
	}

	.buttonOpen2 {
		top: 1220rpx;
		background: linear-gradient(180deg, #FFFFFF 0%, #FFE8D4 32%, #FFECD7 52%, #FFFFFF 100%);
		color: #FD535A;
	}

	.buttonOpen3 {
		color: #FD535A;
	}

	.buttonOpen::after {
		display: none;
	}

	.mt162 {
		margin-top: 128rpx;
	}

	.ljdz {
		background: linear-gradient(180deg, #FE7320 0%, #FE8027 100%);
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		padding: 4rpx 36rpx;
		color: #fff;
	}

	.c1a {
		color: #1A1A1A;
	}

	.a1 {
		padding: 12rpx 24rpx;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
	}


	.a2_1 {
		padding: 44rpx 44rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		background: #FFFFFF;
	}

	.f88 {
		font-size: 64rpx;
	}

	.inviteCraftsmen {
		background-image: url('https://img.aibbyp.com/wechatUser/qyqbac1.png');
		width: 100%;
		height: 1448rpx;

		background-size: 100% 100%;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-repeat: no-repeat;
	}

	.inviteCraftsmen2 {
		background-image: url('https://img.aibbyp.com/wechatUser/fxyqgj.png');
	}

	.inviteCraftsmen3 {
		background-image: url('https://img.aibbyp.com/wechatUser/fxyqsj.png');
	}

	.gjyq {}
</style>